{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Otto测试集测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>id.1</th>\n",
       "      <th>feat_1</th>\n",
       "      <th>feat_2</th>\n",
       "      <th>feat_3</th>\n",
       "      <th>feat_4</th>\n",
       "      <th>feat_5</th>\n",
       "      <th>feat_6</th>\n",
       "      <th>feat_7</th>\n",
       "      <th>feat_8</th>\n",
       "      <th>...</th>\n",
       "      <th>feat_84</th>\n",
       "      <th>feat_85</th>\n",
       "      <th>feat_86</th>\n",
       "      <th>feat_87</th>\n",
       "      <th>feat_88</th>\n",
       "      <th>feat_89</th>\n",
       "      <th>feat_90</th>\n",
       "      <th>feat_91</th>\n",
       "      <th>feat_92</th>\n",
       "      <th>feat_93</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>-1.732039</td>\n",
       "      <td>1.098657</td>\n",
       "      <td>1.376012</td>\n",
       "      <td>4.442086</td>\n",
       "      <td>5.347260</td>\n",
       "      <td>-0.166831</td>\n",
       "      <td>-0.115783</td>\n",
       "      <td>-0.187209</td>\n",
       "      <td>-0.291837</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.058195</td>\n",
       "      <td>-0.282505</td>\n",
       "      <td>-0.420787</td>\n",
       "      <td>-0.248378</td>\n",
       "      <td>-0.418913</td>\n",
       "      <td>2.179874</td>\n",
       "      <td>-0.17682</td>\n",
       "      <td>-0.130768</td>\n",
       "      <td>1.600551</td>\n",
       "      <td>-0.101847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>-1.732015</td>\n",
       "      <td>-0.262923</td>\n",
       "      <td>0.583562</td>\n",
       "      <td>3.763914</td>\n",
       "      <td>0.077039</td>\n",
       "      <td>-0.166831</td>\n",
       "      <td>-0.115783</td>\n",
       "      <td>-0.187209</td>\n",
       "      <td>-0.291837</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.058195</td>\n",
       "      <td>-0.282505</td>\n",
       "      <td>-0.420787</td>\n",
       "      <td>-0.248378</td>\n",
       "      <td>0.538171</td>\n",
       "      <td>-0.292540</td>\n",
       "      <td>-0.17682</td>\n",
       "      <td>-0.130768</td>\n",
       "      <td>-0.385676</td>\n",
       "      <td>0.665792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>-1.731991</td>\n",
       "      <td>-0.262923</td>\n",
       "      <td>-0.208889</td>\n",
       "      <td>-0.305118</td>\n",
       "      <td>0.077039</td>\n",
       "      <td>-0.166831</td>\n",
       "      <td>-0.115783</td>\n",
       "      <td>-0.187209</td>\n",
       "      <td>-0.291837</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.058195</td>\n",
       "      <td>1.291372</td>\n",
       "      <td>-0.047985</td>\n",
       "      <td>-0.248378</td>\n",
       "      <td>-0.418913</td>\n",
       "      <td>-0.292540</td>\n",
       "      <td>-0.17682</td>\n",
       "      <td>-0.130768</td>\n",
       "      <td>-0.385676</td>\n",
       "      <td>-0.101847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>-1.731967</td>\n",
       "      <td>0.417867</td>\n",
       "      <td>-0.208889</td>\n",
       "      <td>-0.305118</td>\n",
       "      <td>0.077039</td>\n",
       "      <td>-0.166831</td>\n",
       "      <td>-0.115783</td>\n",
       "      <td>0.748039</td>\n",
       "      <td>0.582736</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.058195</td>\n",
       "      <td>-0.282505</td>\n",
       "      <td>-0.420787</td>\n",
       "      <td>-0.248378</td>\n",
       "      <td>-0.418913</td>\n",
       "      <td>-0.292540</td>\n",
       "      <td>-0.17682</td>\n",
       "      <td>4.209454</td>\n",
       "      <td>-0.385676</td>\n",
       "      <td>-0.101847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>-1.731943</td>\n",
       "      <td>-0.262923</td>\n",
       "      <td>-0.208889</td>\n",
       "      <td>-0.305118</td>\n",
       "      <td>-0.274309</td>\n",
       "      <td>-0.166831</td>\n",
       "      <td>-0.115783</td>\n",
       "      <td>-0.187209</td>\n",
       "      <td>-0.291837</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.058195</td>\n",
       "      <td>-0.282505</td>\n",
       "      <td>-0.047985</td>\n",
       "      <td>0.364530</td>\n",
       "      <td>0.059629</td>\n",
       "      <td>-0.292540</td>\n",
       "      <td>-0.17682</td>\n",
       "      <td>-0.130768</td>\n",
       "      <td>-0.385676</td>\n",
       "      <td>-0.101847</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 95 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   id      id.1    feat_1    feat_2    feat_3    feat_4    feat_5    feat_6  \\\n",
       "0   1 -1.732039  1.098657  1.376012  4.442086  5.347260 -0.166831 -0.115783   \n",
       "1   2 -1.732015 -0.262923  0.583562  3.763914  0.077039 -0.166831 -0.115783   \n",
       "2   3 -1.731991 -0.262923 -0.208889 -0.305118  0.077039 -0.166831 -0.115783   \n",
       "3   4 -1.731967  0.417867 -0.208889 -0.305118  0.077039 -0.166831 -0.115783   \n",
       "4   5 -1.731943 -0.262923 -0.208889 -0.305118 -0.274309 -0.166831 -0.115783   \n",
       "\n",
       "     feat_7    feat_8    ...      feat_84   feat_85   feat_86   feat_87  \\\n",
       "0 -0.187209 -0.291837    ...    -0.058195 -0.282505 -0.420787 -0.248378   \n",
       "1 -0.187209 -0.291837    ...    -0.058195 -0.282505 -0.420787 -0.248378   \n",
       "2 -0.187209 -0.291837    ...    -0.058195  1.291372 -0.047985 -0.248378   \n",
       "3  0.748039  0.582736    ...    -0.058195 -0.282505 -0.420787 -0.248378   \n",
       "4 -0.187209 -0.291837    ...    -0.058195 -0.282505 -0.047985  0.364530   \n",
       "\n",
       "    feat_88   feat_89  feat_90   feat_91   feat_92   feat_93  \n",
       "0 -0.418913  2.179874 -0.17682 -0.130768  1.600551 -0.101847  \n",
       "1  0.538171 -0.292540 -0.17682 -0.130768 -0.385676  0.665792  \n",
       "2 -0.418913 -0.292540 -0.17682 -0.130768 -0.385676 -0.101847  \n",
       "3 -0.418913 -0.292540 -0.17682  4.209454 -0.385676 -0.101847  \n",
       "4  0.059629 -0.292540 -0.17682 -0.130768 -0.385676 -0.101847  \n",
       "\n",
       "[5 rows x 95 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dpath = \"./data/\"\n",
    "test = pd.read_csv(dpath + \"Otto_FE_test.csv\")\n",
    "test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "test = test.sample(n=10000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.sparse import csr_matrix\n",
    "test_id = test[\"id\"]\n",
    "X = test.iloc[:,1:94]\n",
    "X = csr_matrix(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle\n",
    "rbfsvc = pickle.load(open(\"Otto_RBFSVC.pkl\",\"rb\"))\n",
    "y_predict = rbfsvc.predict(X) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10000,)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_predict.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
